package com.example.computer_exam_training_sys.controller;

import com.example.computer_exam_training_sys.entity.Feedback_Info;
import com.example.computer_exam_training_sys.service.User_feedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/feedbacks")
@CrossOrigin
public class User_feedbackController {

    @Autowired
    private User_feedbackService feedbackService;

    // 查询所有反馈（分页，前端可指定每页数量）
    @GetMapping("/findAll")
    public List<Feedback_Info> getAllFeedbacks(@RequestParam(defaultValue = "1") int page,
                                               @RequestParam(defaultValue = "5") int pageSize) {
        return feedbackService.selectAllByPage(page, pageSize);
    }

    // 根据ID查询反馈
    @GetMapping("/find/{feedback_id}")
    public Feedback_Info getFeedbackById(@PathVariable("feedback_id") int feedback_id) {
        return feedbackService.selectByID(feedback_id);
    }
    //http://localhost:8080/feedbacks/add
    // 新增反馈
    @PostMapping("/add")
    public int addFeedback(@RequestBody Feedback_Info feedback) {

        return feedbackService.insertFeedback(feedback);
    }

    // 更新反馈
    @PutMapping("/update")
    public int updateFeedback(@RequestBody Feedback_Info feedback) {
        return feedbackService.updateFeedback(feedback);
    }

    // 删除反馈
    @DeleteMapping("/delete/{feedback_id}")
    public int deleteFeedback(@PathVariable("feedback_id") int feedback_id) {
        return feedbackService.deleteFeedback(feedback_id);
    }
}